<template>
  <el-dialog
    title="分配角色"
    :visible="showRoleDialog"
    :before-close="closeDialog"
  >
    <!-- <el-dialog title="分配角色" :visible="showRoleDialog" @close="closeDialog"> -->
    <el-checkbox-group v-model="roleIds">
      <!-- label表示存储的值 -->
      <el-checkbox :label="item.id" v-for="item in roleList" :key="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-col :span="6">
          <el-button @click="btnOK">确定</el-button>
          <el-button @click="closeDialog">取消</el-button>
        </el-col>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { getUserDetailByid } from '@/api/user'
import { assignRoles } from '@/api/employee'
export default {
  name: 'role',
  data() {
    return {
      checkList: [], //  所有角色
      roleIds: [], //  用户角色
      userId: ''
    } //
  },
  props: {
    showRoleDialog: {
      type: Boolean,
      required: true,
      default: false
    },
    roleList: { type: Array, required: true }
  },
  created() {},
  watch: {},
  methods: {
    async getUserDetailByid(id) {
      this.userId = id
      const { roleIds } = await getUserDetailByid(id)
      this.roleIds = roleIds
    },
    async btnOK() {
      await assignRoles({ id: this.userId, roleIds: this.roleIds })
      // 调用接口,更新数据

      this.$emit('update:showRoleDialog', false)
    },
    closeDialog() {
      ;(this.roleIds = []), this.$emit('update:showRoleDialog', false)
    }
  }
}
</script>

<style>
</style>